package vip.xiaonuo.smzq.modular.deom;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.json.JSONUtil;

import java.io.File;
import java.util.Date;
import java.util.List;
import java.util.Scanner;

public class NumSpecificationDeom {


    //获取文件编码
    public static String getZlbm(String kyqklx, String kyqdjlx, String jdlx, int count) {
        String zlbm = "";
        //时间戳
        String timeNum = DateUtil.format(new Date(), "YYYYMMdd");
        List<NumEntity> nums = JSONUtil.toList(ResourceUtil.readUtf8Str("json" + File.separator + "num.json"), NumEntity.class);
        for (NumEntity num : nums) {
            if (kyqklx.equals(num.getMc())) {
                kyqklx = num.getDm();
            } else if (kyqdjlx.equals(num.getMc())) {
                kyqdjlx = num.getDm();
            } else if (jdlx.equals(num.getMc())) {
                jdlx = num.getDm();
            }
        }
        if ((count - 10) >= 0) {
            zlbm = kyqklx + kyqdjlx + timeNum + jdlx + count;
        } else {
            zlbm = kyqklx + kyqdjlx + timeNum + jdlx + "0" + count;
        }

        return zlbm;

    }




    /**
     * 生成编码demo
     * @param args
     */
    public static void main(String[] args) {
        //创建一个扫描器对象，用于接收键盘数据
        Scanner scanner = new Scanner(System.in);
        //nextLine方式接收字符串(可以接收空格)
        System.out.println("生成编码类型:1.矿业权编码，2资料编码");
        //判断用户还有没有输入字符
        if (scanner.hasNextLine()) {
            String str = scanner.nextLine();
          if ("1".equals(str)){
              System.out.println("矿产编码:"+getKcNum());
          }else if ("2".equals(str)){
              System.out.println("资料编码:"+getZlNum());
          }else{
              System.out.println("输入有误，请重新输入");
          }
        }
        scanner.close();

}
public static String getKcNum(){
    //时间戳
    String timeNum= DateUtil.format(new Date(), "YYYY");
    Scanner scanner = new Scanner(System.in);
    System.out.println("请输入行政区编码:130100");
    String cityNum = scanner.nextLine();
    System.out.println("请输入矿山类型（未利用，生产，关闭，压覆）:");
    String mineType = scanner.nextLine();
    System.out.println("请输入矿产编号:101");
    String mineSequenceNum = scanner.nextLine();
    System.out.println("请输入矿业权变换类型(新立，变更，分立，整合):");
    String mineTypeNum = scanner.nextLine();
    System.out.println("请输入矿业权变换类型(延续，保留，压覆):");
    String mineTypeNum2 = scanner.nextLine();
    System.out.println("请输入矿业权变更次数:");
    String stateNum = scanner.nextLine();
    if (stateNum.length()<2){
        stateNum= String.format("%02d", Integer.valueOf(stateNum));
    }
    scanner.close();
    List<NumEntity> nums=JSONUtil.toList(ResourceUtil.readUtf8Str("json" + File.separator + "num.json"), NumEntity.class);
    for (NumEntity num : nums) {
        if (mineType.equals(num.getMc())){
            mineType=num.getDm();
        }
        else if (mineTypeNum.equals(num.getMc())){
            mineTypeNum=num.getDm();
        }
        else if (mineTypeNum2.equals(num.getMc())){
            mineTypeNum2=num.getDm();
        }
    }
    return cityNum+mineSequenceNum+mineType+mineTypeNum+timeNum+mineTypeNum2+stateNum+"001";
}
public static String getZlNum(){
    //时间戳
    String timeNum= DateUtil.format(new Date(), "YYYYMMdd");
    Scanner scanner = new Scanner(System.in);
    System.out.println("请输入矿业权库类型（无矿业权库，探矿权库，采矿权库）:");
    String cityNum = scanner.nextLine();

    System.out.println("请输入矿业权登记类型(新立，变更，延续，保留，转让，注销):");
    String mineTypeNum = scanner.nextLine();

    System.out.println("请输入节点类型(半节点，节点):");
    String mineTypeNum2 = scanner.nextLine();
    scanner.close();


    List<NumEntity> nums=JSONUtil.toList(ResourceUtil.readUtf8Str("json" + File.separator + "num.json"), NumEntity.class);
    for (NumEntity num : nums) {
        if (cityNum.equals(num.getMc())){
            cityNum=num.getDm();
        }
        else if (mineTypeNum.equals(num.getMc())){
            mineTypeNum=num.getDm();
        }
        else if (mineTypeNum2.equals(num.getMc())){
            mineTypeNum2=num.getDm();
        }
    }

    return cityNum+mineTypeNum+timeNum+mineTypeNum2+"01";
}

}
